/**
*      author: Y_Yao
*      created: 2024-09-28 14:43:13
**/

#include<bits/stdc++.h>

using namespace std;
using LL = long long;
const int INF = 0x3f3f3f3f;
int a[4];
bool vis[4];
bool vis1;

double count(int i,double num,int b)
{
    switch(i)
    {
        case 0:
            return num + b;
        break;
        case 1:
            return num - b; 
        break;
        case 2:
            return num * b;
        break;
        case 3:
            return num / b;
        break;
    }
    return 0;
}

void dfs(int n,double num)
{

    if(n >= 4)
    {
        if(num == 24)
        {
            vis1 = true;
            cout << "YES" << endl;
            return;
        }
        else return;
    }
    if(vis1) return;

    for(int i = 0;i < 4;i++)
    {
        if(vis[i]) continue;
        vis[i] = true;
        for(int j = 0;j < 4;j++)
        {
            dfs(n + 1,count(j,num,a[i]));
        }
        vis[i] = false;
    }
}

void solve()
{
    string tmp;
    for(int i = 0;i < 4;i++)
    {
        cin >> tmp;
        if(tmp == "A") a[i] = 1;
        else if(tmp == "J") a[i] = 11;
        else if(tmp == "Q") a[i] = 12;
        else if(tmp == "K") a[i] = 13;
        else a[i] = stoi(tmp);
    }
    dfs(0,0);
    if(vis1 == false)
    {
        cout << "NO" << endl;
        return;
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    cin >> t;
    while(t--)
    {
        solve();
        vis1 = false;
    }
    return 0;
}